# RUN: %as %s -o %t.o
# RUN: %objdump -d %t.o | tail -n +6 > %t.txt
# RUN: diff %t.txt %S/../expected/DMAtest.txt
.global start                
_begin:
start:
.section .vector
#.ent main

.exptable:
jmp  exp_lable0||         #bus error 0
nop||
nop||
nop||

jmp  exp_lable1||         #bus error 1        
nop||
nop||
nop||

jmp  exp_lable2||        #bus error 2
nop||
nop||
nop||

jmp  exp_lable3||         #bus error 3
nop||
nop||
nop||

jmp  exp_lable4||         #exception illegale instruction 
nop||
nop||
nop||

jmp  exp_lable5||         #exception overflow
nop||
nop||
nop||

jmp  exp_lable6||         # exception illegale address
nop||
nop||
nop||

jmp  exp_lable7||          # exception 3
nop||
nop||
nop||

jmp  exp_lable8||          #unavoided pic 0
nop||
nop||
nop||

jmp  exp_lable9||          #unavoided pic 1 (wathc dog)
nop||
nop||
nop||

jmp  exp_lablea||          #inner pic 2
nop||
nop||
nop||

jmp  exp_lableb||           #timer pic
nop||
nop||
nop||

jmp  exp_lablec||           # outer pic 4
nop||
nop||
nop||

jmp  exp_labled||          # outer pic 5
nop||
nop||
nop||

jmp  exp_lablee||          # outer pic 6
nop||
nop||
nop||

jmp  exp_lablef||          # outer pic 7
nop||
nop||
nop||

exp_lable0:
movigl GR0 0||
rtt||
nop||
nop||

exp_lable1:
movigl GR0 1||
rtt||
nop||
nop||

exp_lable2:
movigl GR0 1||
rtt||
nop||
nop||

exp_lable3:
movigl GR0 3||
rtt||
nop||
nop||

exp_lable4:
movigl GR0 4||
rtt||
nop||
nop||

exp_lable5:
movigh GR30 0x007f||
movigl GR30 0x3200||
|LOAD32 GR29 GR30 3|
neqi GR29 0x00||
jc rtgr1_lab||
nop||
nop||
movigh GR0 0x7fff||
movigl GR0 0xffff||
jmp rs_lab||
nop||
nop||

rtgr1_lab:
neqi GR29 0x01||
jc rtgr2_lab||
nop||
nop||
movigh GR1 0x7fff||
movigl GR1 0xffff||
jmp rs_lab||
nop||
nop||

rtgr2_lab:
neqi GR29 0x02||
jc rtgr3_lab||
nop||
nop||
movigh GR2 0x7fff||
movigl GR2 0xffff||
jmp rs_lab||
nop||
nop||

rtgr3_lab:
neqi GR29 0x02||
jc rt_rest_lab||
nop||
nop||
movigh GR3 0x7fff||
movigl GR3 0xffff||
jmp rs_lab||
nop||
nop||

rt_rest_lab:
movigh GR4 0x0000||
movigh GR5 0x0000||
movigh GR6 0x0000||
movigh GR7 0x0000||
movigh GR8 0x0000||
movigh GR9 0x0000||
movigh GR10 0x0000||
movigh GR11 0x0000||
movigh GR12 0x0000||
movigh GR13 0x0000||
movigh GR14 0x0000||
movigl GR4 0x0000||
movigl GR5 0x0000||
movigl GR6 0x0000||
movigl GR7 0x0000||
movigl GR8 0x0000||
movigl GR9 0x0000||
movigl GR10 0x0000||
movigl GR11 0x0000||
movigl GR12 0x0000||
movigl GR13 0x0000||
movigl GR14 0x0000||

#todo ...
rs_lab:
|LOAD32 GR29 GR30 2|
neqi GR29 0x00||
jc rsgr1_lab||
nop||
nop||
movigh GR0 0x0000||
movigl GR0 0x0000||
jmp finish_o_lab||
nop||
nop||

rsgr1_lab:
neqi GR29 0x01||
jc rsgr2_lab||
nop||
nop||
movigh GR1 0x0000||
movigl GR1 0x0000||
jmp finish_o_lab||
nop||
nop||

rsgr2_lab:
neqi GR29 0x02||
jc rsgr3_lab||
nop||
nop||
movigh GR2 0x0000||
movigl GR2 0x0000||
jmp finish_o_lab||
nop||
nop||

rsgr3_lab:
neqi GR29 0x02||
jc rs_rest_lab||
nop||
nop||
movigh GR3 0x0000||
movigl GR3 0x0000||
jmp finish_o_lab||
nop||
nop||

rs_rest_lab:
movigh GR4 0x0000||
movigh GR5 0x0000||
movigh GR6 0x0000||
movigh GR7 0x0000||
movigh GR8 0x0000||
movigh GR9 0x0000||
movigh GR10 0x0000||
movigh GR11 0x0000||
movigh GR12 0x0000||
movigh GR13 0x0000||
movigh GR14 0x0000||

movigl GR4 0xbeef||
movigl GR5 0xbeef||
movigl GR6 0xbeef||
movigl GR7 0xbeef||
movigl GR8 0xbeef||
movigl GR9 0xbeef||
movigl GR10 0xbeef||
movigl GR11 0xbeef||
movigl GR12 0xbeef||
movigl GR13 0xbeef||
movigl GR14 0xbeef||
finish_o_lab:
nop||
nop||
rtt||
nop||
nop||

exp_lable6:
movigl GR0 6||
rtt||
nop||
nop||

exp_lable7:
movigl GR0 7||
rtt||
nop||
nop||

exp_lable8:
movigl GR0 8||
rtt||
nop||
nop||

exp_lable9:
movigl GR0 9||
rtt||
nop||
nop||

exp_lablea:
movigl GR0 10||
rtt||
nop||
nop||

exp_lableb:
movigl GR0 11||
rtt||
nop||
nop||

exp_lablec:
movigl GR0 12||
rtt||
nop||
nop||

exp_labled:
movigl GR0 13||
rtt||
nop||
nop||

exp_lablee:
movigl GR0 14||
rtt||
nop||
nop||

exp_lablef:
movigl GR0 15||
rtt||
nop||
nop||


boot:
.section .qxinit

movigh GR0 0x0000||
movigl GR0 0x0000||
movg2g GR1 GR0||
movg2g GR2 GR0||
movg2g GR3 GR0||
movg2g GR4 GR0||
movg2g GR5 GR0||
movg2g GR6 GR0||
movg2g GR7 GR0||
movg2g GR8 GR0||
movg2g GR9 GR0||
movg2g GR10 GR0||
movg2g GR11 GR0||
movg2g GR12 GR0||
movg2g GR13 GR0||
movg2g GR14 GR0||
movg2g GR15 GR0||
movg2g GR16 GR0||
movg2g GR17 GR0||
movg2g GR18 GR0||
movg2g GR19 GR0||
movg2g GR20 GR0||
movg2g GR21 GR0||
movg2g GR22 GR0||
movg2g GR23 GR0||
movg2g GR24 GR0||
movg2g GR25 GR0||
movg2g GR26 GR0||
movg2g GR27 GR0||
movg2g GR28 GR0||
movg2g GR29 GR0||
movg2g GR30 GR0||
movg2g GR31 GR0||

movigh GR28 0x0100||
movigl GR28 0x1000||
movigh GR13 0x0000||
movigl GR13 0x0004||
||store32 GR13 GR28 0

movigl GR5 0x005a||
movigl GR6 0x0a74||
||store8 GR5 GR6 0
movigl GR9 0x0080||
loop GR9 loopend1||
nop||
nop||
addi GR5 GR5 1||
addi GR6 GR6 1||
||store8 GR5 GR6 0
loopend1:
nop||
nop||
nop||

#DMA_init
movigh GR3 0x0100||
movigl GR3 0x9010||
movigh GR2 0x0000||
movigl GR2 0x0001||
||store32 GR2 GR3 0
nop|nop|nop
nop|nop|nop
nop|nop|nop
nop|nop|nop
movigl GR2 0x0003||
||store32 GR2 GR3 0
nop|nop|nop
nop|nop|nop

movigl GR3 0x9180||
movigl GR2 0||
||store32 GR2 GR3 0
nop|nop|nop
nop|nop|nop
movigh GR4 0x0100||
movigl GR4 0x9018||
movigl GR2 0x100||
||store32 GR2 GR4 0
nop|nop|nop
nop|nop|nop
nop|nop|nop

movigl GR3 0x9280||
movigl GR2 0||
||store32 GR2 GR3 0
nop|nop|nop
nop|nop|nop
movigl GR4 0x9018||
movigl GR2 0x300||
||store32 GR2 GR4 0
nop|nop|nop
nop|nop|nop
nop|nop|nop

movigl GR3 0x9380||
movigl GR2 0||
||store32 GR2 GR3 0
nop|nop|nop
nop|nop|nop
movigl GR4 0x9018||
movigl GR2 0x700||
||store32 GR2 GR4 0
nop|nop|nop
nop|nop|nop
nop|nop|nop

movigl GR3 0x9480||
movigl GR2 0||
||store32 GR2 GR3 0
nop|nop|nop
nop|nop|nop
movigl GR4 0x9018||
movigl GR2 0xf00||
||store32 GR2 GR4 0
nop|nop|nop
nop|nop|nop
nop|nop|nop

movigl GR3 0x9580||
movigl GR2 0||
||store32 GR2 GR3 0
nop|nop|nop
nop|nop|nop
movigl GR4 0x9018||
movigl GR2 0x1f00||
||store32 GR2 GR4 0
nop|nop|nop
nop|nop|nop
nop|nop|nop

movigl GR3 0x9680||
movigl GR2 0||
||store32 GR2 GR3 0
nop|nop|nop
nop|nop|nop
movigl GR4 0x9018||
movigl GR2 0x3f00||
||store32 GR2 GR4 0
nop|nop|nop
nop|nop|nop
nop|nop|nop

#DMA_chanConfig
movigh GR3 0x0100||
movigl GR3 0x9120||
movigh GR2 0x0000||
movigl GR2 0x0000||
||store32 GR2 GR3 0
nop|nop|nop
nop|nop|nop
movigl GR3 0x9124||
movigl GR2 0x18||
||store32 GR2 GR3 0
nop|nop|nop
nop|nop|nop
nop|nop|nop

movigl GR3 0x9118||
movigl GR2 0x900||
||store32 GR2 GR3 0
nop|nop|nop
nop|nop|nop
nop|nop|nop

movigl GR3 0x9110||
movigl GR2 0xb||
||store32 GR2 GR3 0
nop|nop|nop
nop|nop|nop
nop|nop|nop

movigl GR3 0x9100||
movigl GR2 0xa74||
||store32 GR2 GR3 0
nop|nop|nop
nop|nop|nop
movigl GR3 0x9104||
movigl GR2 0||
||store32 GR2 GR3 0
nop|nop|nop
nop|nop|nop
movigl GR3 0x9108||
movigl GR2 0xaf4||
||store32 GR2 GR3 0
nop|nop|nop
nop|nop|nop
movigl GR3 0x910c||
movigl GR2 0||
||store32 GR2 GR3 0
nop|nop|nop
nop|nop|nop
nop|nop|nop

movigl GR3 0x9190||
movigh GR2 0x0017||
movigl GR2 0xaff2||
||store32 GR2 GR3 0
nop|nop|nop
nop|nop|nop
nop|nop|nop

movigl GR3 0x9180||
movigh GR2 0x2017||
movigl GR2 0xaff2||
||store32 GR2 GR3 0
nop|nop|nop
nop|nop|nop
nop|nop|nop

movigl GR3 0x9018||
movigh GR2 0||
movigl GR2 0x3f01||
||store32 GR2 GR3 0
nop|nop|nop
nop|nop|nop
nop|nop|nop
nop|nop|nop
nop|nop|nop
nop|nop|nop
nop|nop|nop
nop|nop|nop
nop|nop|nop
nop|nop|nop
nop|nop|nop
nop|nop|nop
nop|nop|nop
nop|nop|nop
nop|nop|nop
nop|nop|nop
nop|nop|nop
nop|nop|nop
nop|nop|nop
nop|nop|nop
nop|nop|nop
nop|nop|nop
nop|nop|nop
nop|nop|nop
nop|nop|nop
nop|nop|nop
nop|nop|nop
nop|nop|nop

movigl GR5 0||
movigl GR6 0x0af4||
|load8 GR5 GR6 0|
addi GR6 GR6 1||
|load8 GR5 GR6 0|
addi GR6 GR6 1||
|load8 GR5 GR6 0|
addi GR6 GR6 1||
|load8 GR5 GR6 0|
addi GR6 GR6 1||
|load8 GR5 GR6 0|
addi GR6 GR6 1||
|load8 GR5 GR6 0|
addi GR6 GR6 1||
|load8 GR5 GR6 0|
addi GR6 GR6 1||
|load8 GR5 GR6 0|
addi GR6 GR6 1||
|load8 GR5 GR6 0|
addi GR6 GR6 1||
|load8 GR5 GR6 0|
addi GR6 GR6 1||
|load8 GR5 GR6 0|

movigh GR30 0||
movigl GR30 0||
movigh GR9 0||
movigl GR9 0x1000||
loop GR9 loopend4||
nop|nop|nop
nop|nop|nop
nop|nop|nop
nop|nop|nop
nop|nop|nop
nop|nop|nop
nop|nop|nop
nop|nop|nop
nop|nop|nop
nop|nop|nop
nop|nop|nop
nop|nop|nop
nop|nop|nop
nop|nop|nop
nop|nop|nop
nop|nop|nop
nop|nop|nop
nop|nop|nop
nop|nop|nop
nop|nop|nop
nop|nop|nop
nop|nop|nop
nop|nop|nop
nop|nop|nop
nop|nop|nop
nop|nop|nop
nop|nop|nop
nop|nop|nop

loopend4:
nop||
movigl GR5 0||
movigl GR6 0x0af4||
|load8 GR5 GR6 0|
movigl GR9 0x0090||
loop GR9 loopend5||
nop||
nop||
addi GR6 GR6 1||
|load8 GR5 GR6 0|

loopend5:
nop|nop|nop
myloop:
nop|nop|nop
nop|nop|nop
nop|nop|nop
nop|nop|nop
jmp myloop||
nop|nop|nop
nop|nop|nop
nop|nop|nop
nop|nop|nop

